source config.sh

if [ "$1" = "" ];then
	echo "Please input user"
	exit
fi
if [ "$2" = "" ];then
	echo "Please input server ID"
	exit
fi
user=$1
ServerID=$2

User=ubuntu
Date=$(date '+%Y-%m-%d-%H-%M-%S')
DestDir=$SSHOuts/$Date
echo "$ExecuteAllRelatedClients: $DestDir"
mkdir $DestDir

$GetAllRelatedInstances $user $ServerID | while read line; 
do 
	instance=$(echo "$line"| awk {'print $1'})
	if [ "$instance" = "$ServerID" ];then
		continue
	fi
	ifRunning=$(echo "$line"| awk {'print $2'})
	IP=$(echo "$line"| awk {'print $4'})
	echo "$ExecuteAllRelatedClients: $instance $ifRunning"
	if [ "$ifRunning" != "running" ];then
		echo "$ExecuteAllRelatedClients: $instace is not in \"running\" state"
	fi		
	echo "$ExecuteAllRelatedClients: $user $instance -> connecting to client $IP"
	(cat $ClientCommands | ssh -oStrictHostKeyChecking=no -i $KeyPairPEM $User@$IP sh >> $DestDir/$IP.txt) &
done

exit

# 
